package com.yangfei.mystudy1020.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.yangfei.mystudy1020.R;
import com.yangfei.mystudy1020.View.MaskView;

import java.util.TimerTask;

public class MaskDrawActivity extends AppCompatActivity {

    public MaskView mMv;
    public int percent = 0;
    java.util.Timer timer = new java.util.Timer(true);

    TimerTask task = new TimerTask() {
        public void run() {
            percent++;
            if(percent>100)
                percent = 0;

            Message message = new Message();
            message.what = 1;
            doActionHandler.sendMessage(message);
        }
    };

    private Handler doActionHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int msgId = msg.what;
            switch (msgId) {
                case 1:
                    MaskDrawActivity.this.mMv.setPercent(percent);
                    break;
                default:
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mask_draw);
        mMv = findViewById(R.id.mv_mask);

        timer.schedule(task, 0, 100);
    }


}
